package org.baicaixiaozhan.springbootwebdemo1.controller;

import lombok.extern.slf4j.Slf4j;
import org.baicaixiaozhan.springbootwebdemo1.annotation.PreAuthorize;
import org.baicaixiaozhan.springbootwebdemo1.util.HttpUtils;
import org.baicaixiaozhan.springbootwebdemo1.util.ResultTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author baicaixiaozhan
 * @since 2021/1/29
 */
@RestController
@RequestMapping("/api")
@Slf4j
public class IndexController {

    @PreAuthorize(roles = "ROLE_STUDENT")
    @GetMapping("/index")
    public ResultTemplate<Object> toIndex() {
        return ResultTemplate.success("successful");
    }

    @PreAuthorize(value = "hasRole('ROLE_STUDENT')")
    @GetMapping("/testSpEL")
    public ResultTemplate<Object> testSpEL() {
        return ResultTemplate.success("successful");
    }

    @PostMapping("/login")
    public ResultTemplate<Object> toLogin() {
        log.info("user : {}", HttpUtils.getCurrentLoginUser());
        return ResultTemplate.success();
    }
}
